﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizzCommInterfaces; 

namespace BizzCore
{
    public class Condition_greaterOrEqualsTo : Condition
    {
        public Condition_greaterOrEqualsTo()
        {
            base._name = ">=";
        }

        public override bool evaluateCondition(MsgAttribute attribute, string field, string expectedValue)
        {
            bool ret = true;
            switch (attribute.Type)
            {
                case BizzCommInterfaces.AttType.text:
                    //ret &= ((string)attribute.Value).CompareTo(expectedValue) >= 0;
                    ret &= String.Compare((string)attribute.Value, expectedValue, true) >= 0;
                    break;
                case BizzCommInterfaces.AttType.number:
                    ret &= Int32.Parse(attribute.Value) >= Int32.Parse(expectedValue);
                    break;
                case BizzCommInterfaces.AttType.boolean:
                    ret &= getBool(Boolean.Parse(attribute.Value), Boolean.Parse(expectedValue));
                    break;
                case BizzCommInterfaces.AttType.date:
                    ret &= DateTime.Parse(attribute.Value) >= DateTime.Parse(expectedValue);
                    break;
                default:
                    ret &= String.Compare((string)attribute.Value, expectedValue, true) >= 0;
                    break;
            }
            return ret;
        }

        private bool getBool(bool boolAttribute, bool boolRule)
        {
            bool ret = (boolAttribute == boolRule) || (boolAttribute);
            return ret;
        }

    }
}
